﻿using System;
using System.Data;
using System.Collections.Generic;
using System.IO;
using Oracle.DataAccess.Client;
using Wicresoft.SelfService.DAO;
using System.Linq;
using System.Configuration;
using System.Web;
using System.Text;

namespace Wicresoft.SelfService.DAL
{
    public class ITSMEventTypeDAL : IDisposable
    {
        public OracleDataAccess oda;
        public OracleTransaction oTran;
        string ConnectionString1 = ConfigurationManager.ConnectionStrings["ITSMContext"].ConnectionString;
        public ITSMEventTypeDAL()
        {
            oda = new OracleDataAccess(ConnectionString1);

            oda.Open();
        }

        private EventType createEventType(OracleDataReader dr)
        {

            EventType et = new EventType();
            et.Request_id = dr["Request_id"].ToString();
            et.Submitter = dr["Submitter"].ToString();
            et.Create_Date = dr["Create_Date"].ToString();
            et.Assigned_To = dr["Assigned_To"].ToString();
            et.Last_Modified_By = dr["Last_Modified_By"].ToString();
            et.Modified_Date = dr["Modified_Date"].ToString();
            et.Status = Convert.ToInt32(dr["Status"]);
            et.Short_Description = dr["Short_Description"].ToString();
            et.Dynamic_Company = dr["Dynamic_Company"].ToString();
            et.Tier1 = dr["Tier1"].ToString();
            et.Tier2 = dr["Tier2"].ToString();
            et.Tier3 = dr["Tier3"].ToString();
            et.Event_properties = dr["Event_properties"].ToString();
            et.Tier2IsDefault = dr["Tier2IsDefault"].ToString();
            et.Cint_Disabled = dr["Cint_Disabled"].ToString();
            et.Tier3IsDefault = dr["Tier3IsDefault"].ToString();
            return et;
        }

        public List<EventType> getAllServiceEventType()
        {
            List<EventType> eventlist = new List<EventType>();
            string sql = "select * from fj_hpd_help_desk_eventtype where event_properties='服务请求' and cint_disabled!=1 and Tier1!='应用系统'";
            using (OracleDataReader dr = oda.ExecuteReader(sql))
            {
                while (dr.Read())
                {
                    EventType bk = createEventType(dr);
                    eventlist.Add(bk);
                }
            }
            return eventlist;
        }

        public List<EventType> getAllBreakEventType()
        {
            List<EventType> eventlist = new List<EventType>();
            string sql = "select * from fj_hpd_help_desk_eventtype where event_properties='用户故障' and cint_disabled!=1";
            using (OracleDataReader dr = oda.ExecuteReader(sql))
            {
                while (dr.Read())
                {
                    EventType bk = createEventType(dr);
                    eventlist.Add(bk);
                }
            }
            return eventlist;
        }

        public void closeDBConnection()
        {
            if (oda != null && oda.conn != null) oda.Close();
        }

        public void Dispose()
        {
            closeDBConnection();
        }

    }
}
